#! /bin/bash
function testMount()
{
sudo touch /home/core/.profile
source /home/core/.profile
source /etc/environment
BOOL_MOUNT="true"
BOOL_MOUNT_SAMBA="true"

if [ ${MOUNT_I} ]
then
for ((i=0;i<$MOUNT_I;i++))
do
    if [[ "${MOUNT_URL[i]}" != "" &&  "${MOUNT_DIR[i]}" != "" ]]
    then
        a=${MOUNT_DIR[i]}
        a=$(df -t nfs | grep "${a}")
        if [ "${a}" == "" ]
        then
            echo "$a has no mount"
            BOOL_MOUNT="false"
        fi
    fi
done
fi

if [ ${MOUNT_SAMBA_I} ]
then
for ((i=0;i<$MOUNT_SAMBA_I;i++))
do
    if [[ "${MOUNT_SAMBA_URL[i]}" != "" && "${MOUNT_SAMBA_DIR[i]}" != "" ]]
    then
        a=${MOUNT_SAMBA_DIR[i]}
        a=$(df -t cifs | grep "${a}")
        if [ "${a}" == "" ]
        then
            echo "$a has no mount"
            BOOL_MOUNT_SAMBA="false"
        fi
    fi
done
fi

if [[ "${BOOL_MOUNT}" = "true" && "${BOOL_MOUNT_SAMBA}" = "true" ]]
then
    return 1
fi

return 0

}

while [ 1 ]
do
    testMount
    if [ $? = 0 ]
    then
        echo "mount data failed,will retry after 10s."
        exit 1
    fi
    sleep 10s
done
